import { headerActionTypes } from './index'
import axios from 'axios'
import { fromJS } from 'immutable'

const changeList = (value = []) => ({
  type: headerActionTypes.CHANGE_LIST,
  value: fromJS(value),
  totalPage: Math.ceil(value.length / 10)
})

export const changeInputStatus = (value) => ({
  type: headerActionTypes.CHANGE_INPUT_STATUS,
  value
})

export const getList = () => {
  return (dispatch) => {
    axios.get('https://www.fastmock.site/mock/117dfab41e7433b4719b831059118248/react_jianshu/api/headerList').then((response) => {
      let list = response.data.data
      dispatch(changeList(list))
    }).catch((e) => {})
  }
}

export const changeMouseEnter = (value) => ({
  type: headerActionTypes.MOUSE_ENTER,
  value
})

export const changeMouseLeave = (value) => ({
  type: headerActionTypes.MOUSE_LEAVE,
  value
})

export const changePage = (page, totalPage) => ({
  type: headerActionTypes.CHANGE_PAGE,
  page,
  totalPage
  
})